package com.alipay.controller;

import com.alipay.common.ResponseCode;
import com.alipay.common.ServerResponse;
import com.alipay.entity.User;
import com.alipay.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.math.BigDecimal;

/**
 * Created by Yancy on 2019/11/9.
 */
@Controller
@RequestMapping("/order/")
public class OrderController {

    @Autowired
    private IOrderService iOrderService;

    @RequestMapping("create")
    @ResponseBody
    public ServerResponse createOrder(HttpSession session, String commodity, BigDecimal amount){
        User user = (User)session.getAttribute("user");
        if(user == null){
            return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),ResponseCode.NEED_LOGIN.getDesc());
        }
        return iOrderService.createOrder(user.getUser_id(),commodity,amount);
    }
}
